import { constantRoutes, asyncRoutes } from '@/router'
// 存放当前的 静态路由 + 当前用户的 权限路由
const state = {
	// 所有人默认拥有静态路由
	routes: constantRoutes
}

const mutations = {
	setRoutes: (state, newRoutes) => {
		state.routes = [...constantRoutes, ...newRoutes]
	}
}

const actions = {
	filterRoutes: (content, menus) => {
		const routes = []
		menus.forEach(item => {
			const res = asyncRoutes.filter(key => {
				return key.name === item
			})
			routes.push(...res)
		})
		content.commit('setRoutes', routes)
		return routes
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
